import React, { useEffect } from "react";

function Temp1() {
  useLogInfo("tem1");
  return <div>temp1</div>;
}
function Temp2() {
  useLogInfo("temp2");
  return <div>temp2</div>;
}

export default function MyHook() {
  useLogInfo("MyHook");
  return (
    <div>
      <h1>MyHook</h1>
      <Temp1></Temp1>
      <Temp2></Temp2>
    </div>
  );
}

function useLogInfo(name) {
  useEffect(() => {
    console.log(`销毁了${name}`);
    return () => {
      console.log(`创建了${name}`);
    };
  });
}
